<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [1, 2, 5, 6, 8, 10]
      function handleData(arr = [], ele) {
        let sum = 0
        for (let i = 0; i < arr.length; i++) {
          sum += arr[i]
        }
        if (ele === true) {
          document.write(`求和为${sum}<br>`)
        } else {
          let average = sum / arr.length
          document.write(`平均数为${average}<br>`)
        }
      }
      let sum = handleData(arr, true)
      let ave = handleData(arr, false)
      // document.write(sum)
    </script>
  </body>
</html>
